<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <title>安亭智慧养老</title>
    <link rel="stylesheet" th:href="${#request.getContextPath()}+'/static/layui/css/layui.css'" media="all">
    <link rel="stylesheet" th:href="${#request.getContextPath()}+'/static/css/thesame.css'" media="all">
    <link rel="stylesheet" th:href="${#request.getContextPath()}+'/static/css/headCss.css'" media="all">
    <link rel="stylesheet" th:href="${#request.getContextPath()}+'/static/css/leftSidebar.css'" media="all">
    <link rel="stylesheet" th:href="${#request.getContextPath()}+'/static/css/rightCon.css'" media="all">
    <link rel="stylesheet" th:href="${#request.getContextPath()}+'/static/css/popCss.css'" media="all"/>
    <style type="text/css">
        .current {background-color:white;color: #1C9399;}
        .layui-layer-rim{border: none !important;}
        .currentSec {background-color: rgba(28, 147, 153, 0.1);color: #1C9399;}
    </style>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
<input type="hidden" id="basePathInput" th:value="${#request.getScheme()+'://'+ #request.getServerName() + ':'+#request.getServerPort()+ #request.getContextPath()}">

<div th:replace="view/sys/head :: head"></div>
<div th:replace="view/sys/left :: left"></div>
<div class="layui-body" style="bottom: 0 !important;">
    <iframe id="mainContainer" name="mainContainer" style="overflow: visible; border: none" width="100%" height="100%" scrolling="no" marginheight="0" marginwidth="0" th:src="${#request.getContextPath()}+'/welcome'"></iframe>
</div>

</div>

<script th:src="${#request.getContextPath()}+'/static/js/jquery-2.1.3.min.js'"></script>
<script th:src="${#request.getContextPath()}+'/static/layui/layui.js'" charset="utf-8"></script>
<script th:inline="javascript">var basePath = [[${#httpServletRequest.getContextPath()}]];</script>
<script>
    //左侧菜单栏
    layui.use(['element','form'],function() {
        var element = layui.element;
        var form = layui.form;
        form.on('select(pensionFilter)', function(data){
            //获取养老机构编号
            var pensionNo =  data.value
            $.ajax({
                url:basePath+'/changePensionInfo',
                type:'post',
                dataType:'json',
                data:{"pensionNo":pensionNo},
                success:function (result) {
                    if(result.code=='0000'){
                        var url = $(".currentSec").attr("data-url");
                        $("#mainContainer").attr("src",basePath + url);
                    }
                }
            })
        });
    });

    $(function(){
        //当新用户登陆系统时，提示需要修改密码
        // var pwdFlag ='[[${pwdFlag}]]';
        // if(pwdFlag==0){
        //     layer.alert("请先进入个人中心修改密码后，才能访问全部菜单", function(){
        //         layer.closeAll();
        //     });
        // }

        //登出
        $("a#loginOut").on("click",function (e) {
            window.location.href = basePath+"/outLogin";
        })

        //获取菜单
        var initMenu = '[[${initMenu}]]';
        getMenu(initMenu);
    })
    /**
     * 获取菜单
     */
    function getMenu(menuNo) {
        //var userNo = '[[${userNo}]]';
        $.ajax({
            url:basePath+"/getMenuByUser",
            type:"post",
            dataType:"json",
            data:{"menuNo":menuNo},
            success:function (result) {
                var userNo = result.msg;
                var initUrl = "";
                //养老院是否下拉
                isSelectAgedHomeShow(menuNo);
                if(result.code == 200){
                    if(menuNo!='CE69C2C9575953DB' && menuNo!='281C2B6D67E87A76'){
                        // 二级菜单
                        let html = '<div class="layui-left-con layui-left-label-con pad12px">';
                        html+='<div class="new-add-box-scroll" style="overflow-y: scroll">';
                        html+='<nav class="label-nav-con">';
                        var count=0;
                        $.each(result.data,function(index,lv1){
                            console.log(lv1);
                            if(lv1.count>=0){
                                html+='<div class="f16px"><img src="' + basePath + '/static/img/' + lv1.ICON + '">'+lv1.NAME+'</div>';
                                html+='<ul class="lh40px f14px">';
                                $.each(lv1.data,function(index,lv2){
                                    html+='<li data-url="'+lv2.URL+'">'+lv2.NAME+'</li>';
                                    count++;
                                })
                            }
                            html+='</ul>';
                        });

                        html+='</nav>';
                        html+='</div>';
                        html+='</div>';
                        $("div#menuArticle").html(html);

                        if(count==0){
                            //不存在菜单时，显示未开通此应用功能，请联系管理员开通
                            initUrl="/unauth";
                            //不存在菜单时，隐藏下拉养老院选择
                            selectAgedHomeHide();
                            //左边一级菜单隐藏
                            $("div#menuArticle").html("");
                        }

                        //二级菜单选中样式
                        $('.label-nav-con li').click(function() {
                            $(this).addClass('currentSec').siblings().removeClass('currentSec');
                        })

                        $("div.layui-left-label-con li").click(function(){
                            var url = $(this).data("url");
                            if(url && "null" != url){
                                window.frames['mainContainer'].location.href= basePath + url;
                            }
                            //$(this).addClass('currentSec').parent().siblings().children().removeClass('currentSec').css("background",rgba(28, 147, 153, 0.1));
                            $(this).addClass('currentSec').parent().siblings().children().removeClass('currentSec');
                        });
                    }else{
                        var count=0;

                        //一级菜单
                        let html = '<ul class="layui-nav layui-nav-tree layui-nav-tree-orgincon" lay-filter="test">';
                        if(result.data && result.data.length > 0){
                            $.each(result.data,function(index,lv1){
                                if(lv1.count>0){
                                    $.each(lv1.data,function (i,v) {
                                        //如果是数据看板，显示统计
                                        if(index==0&&menuNo=='281C2B6D67E87A76'){
                                            initUrl = v.URL;
                                        }
                                        html += '<li data-id="'+v.MENU_NO+'" class="layui-nav-item" data-url="'+v.URL+'"><a href="javascript:;" class="layui-nav-itemed-a"><img src="' + basePath + '/static/img/' + v.ICON + '">' + v.NAME + '</a></li>';
                                    })
                                    count++;
                                }
                            });
                        }
                        if(count==0){
                            //不存在菜单时，显示未开通此应用功能，请联系管理员开通
                            initUrl="/unauth";
                            selectAgedHomeHide();
                        }
                        html += '</ul>';
                        $("div#menuArticle").html(html);


                        $("ul.layui-nav-tree-orgincon li").on("click",function(e){
                            let current = $("ul.layui-nav-tree-orgincon li.layui-nav-itemed-a");
                            let str = $(this).find("img").attr("src");
                            let str1 = str.substring(0,str.lastIndexOf("."));
                            if(str.indexOf("_cur") != -1){
                            }else{
                                $(this).find("img").attr("src",str1+"_cur.png");
                                $(this).siblings().find("img").each(function(i,v){
                                    let emmmm = $(this).attr("src");
                                    if(emmmm.indexOf("_cur") != -1){
                                        $(this).attr("src",emmmm.replace("_cur",""));
                                    }
                                })
                            }
                        })

                        //折叠元素中选中选中样式
                        $("ul.layui-nav-tree-orgincon li").click(function(){
                            var url = $(this).data("url");
                            if(url && "null" != url){
                                window.frames['mainContainer'].location.href= basePath + url;
                            }
                            var selectId = $(this).data("id");
                            $(this).attr("style","background:#1C9399 !important;").find("a").attr("style","color:white !important;");

                            var arr = $(this).parent().find("li");
                            $(arr).each(function (i,obj) {
                                var curId = $(obj).data("id");
                                if(selectId!=curId){
                                    $(obj).attr("style","background:white !important;").find("a").attr("style","color:#666 !important;");
                                }
                            });
                        });
                    }
                    //tab选中
                    layui.use(['element', 'layer'], function() {
                        var element = layui.element;
                        var layer = layui.layer;
                        $('.layui-layout-left-color li').on('click', function() {
                            $(this).children('a').addClass('current').parent().siblings().children().removeClass('current');
                        });
                        //存在初始跳转时，优先跳转初始链接；不存在时，跳默认访问页
                        if(!isNull(initUrl)){
                            $("#mainContainer").attr("src",basePath + initUrl);
                        }else{
                            $("#mainContainer").attr("src",basePath+"/welcome");
                        }
                    });
                }
            }
        })
    }

    /**
     * 下拉敬老院是否显示
     */
    function isSelectAgedHomeShow(menuNo){
        //养老机构时才显示养老院下拉
        if(menuNo=='2758F8EEDCB48A47'){
            // $("#selectAgedHome").val("0");
            $("#agedHome").show();
        }else{
            $("#agedHome").hide();
        }
    }

    /**
     * 下拉敬老院不显示
     */
    function selectAgedHomeHide(){
        $("#agedHome").hide();
    }

    /**
     * 判断是否为空
     */
    function isNull(value) {
        return value == null || value === "" || value === undefined;
    }

</script>
</body>
</html>
